<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "product".
 *
 * @property int $id
 * @property string $name
 * @property string $desc
 * @property int $price
 * @property int $num
 * @property int $click_num
 */
class Product extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'product';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['name'], 'required'],
            [['name'], 'string', 'min' => 1,'max' => 15],
            [['name'],'match','pattern'=>'/^[A-Za-z]+$/','message'=>'name只能是英文'],
            [['desc'], 'string', 'min' => 1,'max' => 200],
            [['desc'],'match','pattern'=>'/^[A-Za-z0-9]+$/','message'=>'desc只能是英文和数字'],
            [['name'], 'string', 'max' => 32],
            [['desc'], 'string', 'max' => 255]
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'name' => 'Name',
            'desc' => 'Desc',
            'price' => 'Price',
            'num' => 'Num',
            'click_num' => 'Click Num',
        ];
    }
}
